﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebSite_that_use_Wizard.NET
{
    public partial class Applications : System.Web.UI.Page
    {
        private Wizard.Asp.AspEngine mWizardEngine;
        private Wizard.IDataStoreContext mDataStoreContext;
        private Wizard.Source.ISession mWizardSession;

        public Applications()
        {
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            mWizardEngine = (Wizard.Asp.AspEngine)Application["WizardEngine"];
            mDataStoreContext = mWizardEngine.DataStore.GetNewContext();
            mWizardSession = mDataStoreContext.GetSession(this.Session.SessionID);
        }

        protected void ViewApplication_Click(object sender, EventArgs e)
        {
            string applicationId = ((LinkButton)sender).CommandArgument;
            Response.Redirect("Application.aspx?id=" + applicationId);
        }

        protected void DeleteApplication_Click(object sender, EventArgs e)
        {
            string applicationId = ((LinkButton)sender).CommandArgument;
            mDataStoreContext.DeleteApplication(int.Parse(applicationId));

        }

        protected void lnkCreateNewApplication_Click1(object sender, EventArgs e)
        {
            Wizard.Source.IWizardApplication newApp = mDataStoreContext.NewApplication("Temp");
            Response.Redirect("Application.aspx?id=" + newApp.ApplicationId.ToString());
        }

        public class ApplicationsHelper
        {
            internal Wizard.IDataStoreContext mDataStoreContext;

            public ApplicationsHelper()
            {
            }

            //public Wizard.Source.ISession[] GetApplications()
            public Wizard.Source.IWizardApplication[] GetApplications()
            {
                return mDataStoreContext.GetApplications();
            }
        }

        protected void ObjectDataSource1_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
        {
            var helper = e.ObjectInstance as ApplicationsHelper;
            helper.mDataStoreContext = this.mDataStoreContext;
        }


   
    }
}
